<?php

/**
* @DEPRECATED  see document/document.php
*/
class NDocument extends NObject {


function &getInstance ($type="html",$attributes)

    // this implements the 'singleton' design pattern.

    {

                 static $instances;
 
                 if (!isset( $instances )) {
                         $instances = array();
                 }
 
                 $signature = serialize(array($type, $attributes));

        if (empty($instances[$signature]))
		{
			$type	= preg_replace('/[^A-Z0-9_\.-]/i', '', $type);
			$path	= dirname(__FILE__).DS.$type.DS.$type.'.php';
			$ntype	= null;

			// Check if the document type exists
			if ( ! file_exists($path))
			{
				// Default to the raw format
				$ntype	= $type;
				$type	= 'raw';
			}

			// Determine the path and class
			$class = 'NDocument'.$type;
			if(!class_exists($class))
			{
				$path	= dirname(__FILE__).DS.$type.DS.$type.'.php';
				if (file_exists($path)) {
					require_once($path);
				} else {
					NError::raiseError(500,NText::_('Unable to load document class'));
				}
			}

			$instance	= new $class($attributes);
			$instances[$signature] =& $instance;

			if ( !is_null($ntype) )
			{
				// Set the type to the Document type originally requested
				$instance->setType($ntype);
			}
		}

		return $instances[$signature];
        

    } // getInstance

function __construct($config){
$this->theme = NFactory::getTheme();
if ($config->theme) $themename=$config->theme;
$this->theme->setTheme($themename);
}
function render($content){
	// scripts
	foreach ($this->_scripts as $url=>$type){
	$this->theme->module_header.="<script type=\"$type\" src=\"$type\"></script>";
	}

$this->theme->set("content",$content);
return  $this->theme->render();

}


function addScript($url, $type="text/javascript") {
	$this->_scripts[$url] = $type;
}

}
?>